import { Injectable } from '@angular/core';
import { Service } from '../../../server/server';
import {MessageService} from 'primeng/api';

@Injectable()
export class HintsService {

  constructor(private service: Service,private messageService:MessageService) { }

  /**
  * 操作提示
  * @param whichHints
  */
  operationHints(hintsTxt: string, whichHints: string) {
    switch (whichHints) {
      case 'success':
        this.service.prompt = { prompt: true, success: true, fail: false, promptStatement: hintsTxt }
        this.service.promptclose;
        break;
      case 'fail':
        this.service.prompt = { prompt: true, success: false, fail: true, promptStatement: hintsTxt }
        this.service.promptclose = [];
        break;
    }
  }

  /**
  * 操作提示
  * @param whichHints
  */
  messages(data: string, code: string) {
    switch (code) {
      case '0000':
        this.messageService.add({severity:'success', detail:data,life:1500})
        break;
      case '9999':
        this.messageService.add({severity:'error', detail:data,life:1500})
        break;
      case 'error':
        this.messageService.add({severity:'error', detail:'操作失败!',life:1500})
        break;
    }
  }

  /**
   * 操作提示
   * @param hintsTxt 
   * @param resultCode 
   */ 
  _operationHints(hintsTxt: string, resultCode: string) {
    if (hintsTxt == 'error') {
      hintsTxt = '操作失败！';
    }
    switch (resultCode) {
      case '0000':
        this.service.prompt = { prompt: true, success: true, fail: false, promptStatement: hintsTxt }
        this.service.promptclose;
        break;
      case 'error':
        this.service.prompt = { prompt: true, success: false, fail: true, promptStatement: hintsTxt }
        this.service.promptclose = [];
        break;
      default: 
        this.service.prompt = { prompt: true, success: false, fail: true, promptStatement: hintsTxt }
        this.service.promptclose = [];
        break;
    }
  }

}
